package com.spark.tags;

import com.spark.core.SparkContext;
import com.spark.core.XMap;


/**
 * 组件基类.
 * 
 * @version $Id: Field.java v 1.0 2009-7-20 上午11:29:55 znjqolf Exp $
 * @author <a href="mailto:znjqolf@126.com">vincent</a>
 * 
 * disabled:是否可用  true|false
 * emptyText:输入提示文字	String
 * className:额外样式名	String
 * style:样式描述			String
 */
public class Field extends ViewComponent {
	
	public static final String CLASSNAME_REQUIRED = "s_rq";
	
	public static final String PROPERTITY_REQUIRED = "required";
	public static final String PROPERTITY_MAXLENGTH = "maxLength";

//	protected String getDefaultClass(XMap view,SparkContext context){
//		String clz = super.getDefaultClass(view, context);		
//		boolean required = view.getBoolean(PROPERTITY_REQUIRED, false);
//		if(required) {
//			clz.concat(" ").concat(CLASSNAME_REQUIRED);
//		}
//		return clz;
//	}
	
	protected String getDefaultClass(XMap view,SparkContext context){
		StringBuilder sb = new StringBuilder(super.getDefaultClass(view, context));
		boolean required = view.getBoolean(PROPERTITY_REQUIRED, false);
		if(required) {
			sb.append(" ").append(CLASSNAME_REQUIRED);
		}
		return sb.toString();
	}
	
	public void init(XMap view, SparkContext context) throws Exception{
		super.init(view, context);
		
		/*************** hidden属性 *************/
//		boolean hidden = view.getBoolean(ComponentConfig.PROPERTITY_HIDDEN, false);
//		if(hidden != false)
//		addConfig(ComponentConfig.PROPERTITY_HIDDEN, Boolean.valueOf(hidden));
		
		
		/*************** required属性 *************/
		boolean notBlank = view.getBoolean(PROPERTITY_REQUIRED, false);
		context.put(PROPERTITY_REQUIRED, notBlank);
		if(notBlank) {
			context.addJsonConfig(PROPERTITY_REQUIRED,notBlank);
		}
		/*****************************************/
		
		/*************** maxLength属性 *************/
		Integer maxlength = view.getInt(PROPERTITY_MAXLENGTH);
		if(maxlength != null)
			context.addJsonConfig(PROPERTITY_MAXLENGTH, maxlength);
		
		
	}
	
	
}
